package com.shundr.shipper.common;

import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;

import com.shundr.shipper.R;
import com.shundr.shipper.base.BaseActivity;
import com.shundr.shipper.common.view.WebViewWithProgress;

/**
 * 公共webview
 * CommonWebView
 * 
 * @author larry 2015-5-12 上午9:46:09 
 * @version 1.0.0
 *
 */
public class CommonWebViewActivity extends BaseActivity{

	private String mTitle = "舜达";
	private String mUrl = "http://www.shundr.com";
	
	private WebView mWebView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_common_webview);
		mUrl = getIntent().getStringExtra("url");
		mTitle = getIntent().getStringExtra("title");
		mActionBar.setTitle(mTitle);
		
		WebViewWithProgress webViewProgress = (WebViewWithProgress)findViewById(R.id.webview);
		mWebView = webViewProgress.getWebView();
		mWebView.getSettings().setJavaScriptEnabled(true); 
		mWebView.getSettings().setBlockNetworkImage(false);
		mWebView.getSettings().setBlockNetworkLoads(false);
		mWebView.getSettings().setDomStorageEnabled(true); 
		// 设置可以支持缩放 
		mWebView.getSettings().setSupportZoom(true); 
		//设置webview为单列显示，是一些大图片适应屏幕宽度
		mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
		mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
		//自适应屏幕  下面这俩好使
		mWebView.getSettings().setUseWideViewPort(true); 
		mWebView.getSettings().setLoadWithOverviewMode(true);
		
		mWebView.loadUrl(mUrl);
	}
	
	/**
	 * 设置回退 覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
			mWebView.goBack(); // goBack()表示返回WebView的上一页面
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onDestroy() {
//		mWebView.destroy();
		super.onDestroy();
	}
	
	
}
